/*]
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package babyroom

import javafx.event._
import javafx.geometry._
import javafx.scene._
import javafx.scene.control._
import javafx.scene.effect._
import javafx.scene.image._
import javafx.scene.input._
import javafx.scene.layout._
import javafx.scene.paint._
import javafx.scene.text._
import javafx.stage._
import javafx.application._
import java.io._
import javax.imageio._
import EventLambdar._

object Main {

  val WIDTH = 375;
  val HEIGHT = 523;
  
  /**
   * @param args the command line arguments
   */
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
    Application.launch(classOf[Main], args: _*)
  }

}

class Main extends Application{
  
  def start(primaryStage: Stage){
    import Builder._
    
    import StageBuilder._
    primaryStage title "hello world."
    
    val card = new Image(ClassLoader.getSystemResourceAsStream("babyroom/resouce/wcard.jpg"))
    val pt = new Image(ClassLoader.getSystemResourceAsStream("babyroom/resouce/wpt.jpg"))
    val name = new Label
    name.textProperty.set("White Knight")
    val matrixb = Font.loadFont(ClassLoader.getSystemResourceAsStream("babyroom/resouce/matrixb.ttf"), 23)
    name.fontProperty.set(matrixb)
    name.prefHeightProperty.set(27)
    
    val mana = new ImageView(new Image(ClassLoader.getSystemResourceAsStream("babyroom/resouce/mana_w.png"), 19, 19, true, true))
    
    val cover = new ImageView(new Image(ClassLoader.getSystemResourceAsStream("babyroom/resouce/The joshua Tree.jpg")))
    cover.viewportProperty.set(new Rectangle2D(32, 60, 312, 230))
    cover.rotateProperty.set(180)
    
    val catalogy = new Label
    catalogy.textProperty.set("Creature-Human Knight")
    catalogy.fontProperty.set(Font.font(matrixb.getFamily, 20))
    catalogy.prefHeightProperty.set(26)
    
    def createManaSymbol = ColumnCell(19, RowCell(6), RowCell(19, new ImageView(mana.imageProperty.get){setRotate(180)}))

    val powerAndWeight = new Label("2/2", new ImageView(pt))
    val mplantin = Font.loadFont(ClassLoader.getSystemResourceAsStream("babyroom/resouce/mplantin.ttf"), 20)
    powerAndWeight.fontProperty.set(Font.font(mplantin.getFamily, FontWeight.BOLD, 20))
    powerAndWeight.contentDisplayProperty.set(ContentDisplay.CENTER)
    
    val a = ImagedPaneBuilder(card, 
                          ColumnCell(card.widthProperty.get,
                                         RowCell(26), 
                                         RowCell(27, ColumnCell(33), ColumnCell(273, name), createManaSymbol, createManaSymbol), 
                                         RowCell(8),
                                         RowCell(230, ColumnCell(31), ColumnCell(312/*, cover*/)),
                                         RowCell(3),
                                         RowCell(26, ColumnCell(35), ColumnCell(312, catalogy)),
                                         RowCell(6),
                                         RowCell(135, ColumnCell(27), ColumnCell(315)),
                                         RowCell(42, ColumnCell(271), ColumnCell(81, powerAndWeight))))
    
    val root = new Group
    root.getChildren.addAll(a)
    val s = new Scene(root)
    
    s.onMouseClickedProperty.set((e: MouseEvent) => {
        println(e.getSceneX)
        println(e.getSceneY)
      })

    
    primaryStage.setScene(s)

    primaryStage show
  }
}